package com.fyj.repository;

import com.fyj.pojo.MyMission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author 钰杰
 * @className MyMissionRepository
 * @description VX:FengYJ996
 * @date 2019/12/411:26
 */
public interface MyMissionRepository extends JpaRepository<MyMission, Integer> {

    @Transactional
    @Modifying
    @Query(value = "UPDATE tb_mission SET solveid = ?1 ,`status` = ?2 , " +
            "tb_mission.pdate = NOW() WHERE tb_mission.id = ?3", nativeQuery = true)
    int updMissionStatus(Integer userid, int statusid, int missionid);

    //按权重排序
    @Query(value = "SELECT * FROM tb_mission ORDER BY `level` DESC" , nativeQuery = true)
    List<MyMission> findAllByLevelDesc();

    //按提交时间排序
    @Query(value = "SELECT * FROM tb_mission ORDER BY cdate ASC",nativeQuery = true)
    List<MyMission> findAllByCdateAsc();


}
